export default {
  namespaced:true,
  state:()=>({
      carList:[
        {
          id:"1",
          imageUrl: "https://cdn13.mei.com/product/TJX-401-00003/896f462953a9763125dc67bb74fa4776749ad824b2af14a5e351bd6863d08f8e.jpg",
          name: "MOSCHINO/莫斯奇诺 19春夏女士松紧腰带喇叭裤腿设计长裤",
          uName:"MOSCHINO",
          color:"黑色",
          price:"3774",
          size:"40",
          isCheck:true,
          num:1
        },
        {
          id:"2",
          imageUrl: "https://cdn13.mei.com/product/TJX-401-00003/896f462953a9763125dc67bb74fa4776749ad824b2af14a5e351bd6863d08f8e.jpg",
          name: "MOSCHINO/莫斯奇诺 19春夏女士松紧腰带喇叭裤腿设计长裤",
          uName:"MOSCHINO",
          color:"黑色",
          price:"3774",
          size:"40",
          isCheck:true,
          num:1
        }
      ]
  }),
  getters:{
    allCheck(state){
      let allCheck=true;
      let onecheck=false; 
      let allprice=0;
      state.carList.forEach((item)=>{
        if(item.isCheck){
          allprice+=item.price*item.num;
          onecheck=true
        }
        
        
        if(!item.isCheck){
          allCheck = false;
        }
      })
      return {
        allCheck,
        allprice,
        onecheck
      }
     
    },
  },
  mutations:{
    checkMut(state,idx){
      state.carList[idx].isCheck = !state.carList[idx].isCheck
    },
    all(state,a){
      state.carList.forEach((item)=>{
        item.isCheck=!a
      })
    },
    plus(state,idx){
      if(state.carList[idx].num<9){
        state.carList[idx].num++
      }
     
    },
    reduce(state,idx){
      if(state.carList[idx].num>1){
        state.carList[idx].num--
      }
      
    }
  }
}